package com.zhanghe.study.mapreduce.friend;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author zh
 * @date 2021/4/2 15:23
 */
public class TwoShareFriendsDriver {
    public static void main(String[] args) throws InterruptedException, IOException, ClassNotFoundException {
        args = new String[]{"/Users/zhanghe/Desktop/user/myself/GitProject/hdfs/src/main/resources/friendinput2","/Users/zhanghe/Desktop/user/myself/GitProject/hdfs/src/main/resources/friendoutput2"};

        Configuration conf = new Configuration();
        // 获取job
        Job job = Job.getInstance(conf);
        // 设置jar的存储位置
        job.setJarByClass(TwoShareFriendsDriver.class);
        // 设置map和reduce
        job.setMapperClass(TwoShareFriendsMapper.class);
        job.setReducerClass(TwoShareFriendsReducer.class);
        // 设置map的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);
        // 设置输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
//        job.setInputFormatClass(CombineFileInputFormat.class);
//        CombineFileInputFormat.setMaxInputSplitSize(job,20*1024*1024);
        // 设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        // 压缩、解压缩
//        DefaultCodec codec = new DefaultCodec();
//        CompressionInputStream compressionInputStream = codec.createInputStream(inputstream);
//        CompressionOutputStream compressionOutputStream = codec.createOutputStream(outputStream);

        // job提交
        job.waitForCompletion(true);
    }
}
